// @ts-ignore
import {ITopic, ITopic_as_TopicStorage, ITopic_Enum, topic_original, TopicStorage} from "./Topic.ts";
import {题目类型} from "./题目类型";
import {Tags_Data} from "./Tag";
import {Ref} from "vue";
import {TopicGroupStorage} from "./TopicStorage";


type topic = {
	topic:ITopic<any> //运行类型
}

export type topic_groups = {
	[topic_name : string]: topic[]
};


export class TopicGroupClass {
	private topic_groups:topic_groups = {};
	/// 谨慎修改
	unsafe_get_topic_groups():topic_groups {
		return this.topic_groups
	}
	/// 加入一个题目 , 不管你设置的index ,优先填入 空缺序号
	add_topic(topic:ITopic<any>,topic_enum:ITopic_Enum):topic{
		const name = topic.topics_name.value;
		if(this.topic_groups[name] == undefined)
			this.topic_groups[name] = []
		let topic_storage = TopicGroupStorage.add_topic({
			itopic_enum:topic_enum,
			topic_storage:ITopic_as_TopicStorage(topic)
		});
		topic.index.value = topic_storage.topic_storage.index;
		this.topic_groups[name][topic_storage.topic_storage.index] = {topic:topic};
		return topic;
	}
	/// 删除一个题目
	remove_topic(topic_group_name:string,index:number){
		delete this.topic_groups[topic_group_name][index];
		TopicGroupStorage.remove_topic(topic_group_name,index);
	}
	/// 获取所有题目组名
	get_topic_name_all():string[]{
		return TopicGroupStorage.get_topic_name_all();
	}
	get_topic_index_max(topic_group_name:string):number | undefined{
		return TopicGroupStorage.get_topic_index_max(topic_group_name)
	}
	get_topic(name:string, index:number):ITopic<any>|undefined{
		console.log(this.topic_groups?.[name]?.[index])
		return this.topic_groups?.[name]?.[index]?.topic
	}
	// todo...
}

export const TopicGroup:TopicGroupClass = TopicGroupStorage.init_TopicGroupClass();


